package com.xinnet.mms.notice.dao.impl;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import com.xinnet.core.dao.impl.BaseDaoImpl;
import com.xinnet.core.utils.page.PageView;
import com.xinnet.mms.entity.Notice;
import com.xinnet.mms.notice.dao.NoticeDao;

@Repository("noticeDao")
public class NoticeDaoImpl extends BaseDaoImpl<Notice, Long> implements NoticeDao {

	/**添加一条消息数据进公告表*/
	@Override
	public void addMessage(Notice notice) throws SQLException {
		this.getSqlSession().insert("notice.addMessage",notice);
	}

	/**查询消息记录*/
	@Override
	public PageView<Notice> queryMessage(PageView<Notice> pageView) throws SQLException {
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("paging", pageView);
		pageView.setRecords(this.getSqlSession().selectList(this.getClassName()+".queryMessage",map));
		return pageView;
	}

	/**通过ID获取消息详情*/
	@Override
	public Notice getMessageById(@Param(value="id") String id) throws SQLException {
		return this.getSqlSession().selectOne("notice.getMessageById",id);
	}

	/**通过ID修改消息内容*/
	@Override
	public void updateMessageById(Notice notice) throws SQLException {
		this.getSqlSession().update("notice.updateMessageById",notice);
	}

	/**通过ID删除消息*/
	@Override
	public void delMessageById(@Param(value="id") String id) throws SQLException {
		this.getSqlSession().delete("notice.delMessageById",id);
	}

	/**标题名模糊查询消息*/
	@Override
	public PageView<Notice> queryMsgByTitle(PageView<Notice> pageView,Notice notice) throws SQLException {
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("paging", pageView);
		map.put("t", notice);
		pageView.setRecords(this.getSqlSession().selectList(this.getClassName()+".queryMsgByTitle",map));
		return pageView;
	}

	/**获取政策公告列表*/
	@Override
	public PageView<Notice> queryPolicy(PageView<Notice> pageView) throws SQLException {
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("paging", pageView);
		pageView.setRecords(this.getSqlSession().selectList(this.getClassName()+".queryPolicy",map));
		return pageView;
	}

	/**带查询条件获取政策公告列表*/
	@Override
	public PageView<Notice> queryPolicy(PageView<Notice> pageView, Notice notice) throws SQLException {
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("paging", pageView);
		map.put("t", notice);
		pageView.setRecords(this.getSqlSession().selectList(this.getClassName()+".queryPolicyByMap",map));
		return pageView;
	}

	/**添加公告*/
	@Override
	public void addPolicy(Notice notice) throws SQLException {
		this.getSqlSession().insert("notice.addPolicy",notice);
	}

	/**通过ID获取公告详情*/
	@Override
	public Notice getPolicyById(@Param(value="id") String id) throws SQLException {
		return this.getSqlSession().selectOne("notice.getPolicyById",id);
	}

	/**通过ID修改公告内容*/
	@Override
	public void updatePolicyById(Notice notice) throws SQLException {
		this.getSqlSession().update("notice.updatePolicyById",notice);
	}

	/**通过ID删除公告*/
	@Override
	public void delPolicyById(@Param(value="id") String id) throws SQLException {
		this.getSqlSession().delete("notice.delPolicyById",id);
	}

	/**查询六条政策公告*/
	@Override
	public List<Notice> getPolicyInMain() throws SQLException {
		return this.getSqlSession().selectList("notice.getPolicyInMain");
	}

	/**查询六条动态消息*/
	@Override
	public List<Notice> getMsgInMain() throws SQLException {
		return this.getSqlSession().selectList("notice.getMsgInMain");
	}
}
